<?php


namespace app\model;

use think\Model;
class ConfigModel extends Model
{
    protected $table = 'store_config';

    /**
     * @param $user_id
     * @return ConfigModel[]|array|\think\Collection
     * @throws \think\db\exception\DataNotFoundException
     * @throws \think\db\exception\DbException
     * @throws \think\db\exception\ModelNotFoundException
     * @notes 包装
     * @author: dongdong
     * @date: 2025/1/1 11:40
     */
    public function package($user_id=0){
        try {
            return self::where(['type'=>1])->where("user_id","in","0")->where("status=1 and is_deleted=0")->field("id,title,title_ru")->select();
        }catch (\Exception $e){
            return [];
        }
    }

    /**
     * @return ConfigModel[]|array|\think\Collection
     * @throws \think\db\exception\DataNotFoundException
     * @throws \think\db\exception\DbException
     * @throws \think\db\exception\ModelNotFoundException
     * @notes 卸货方式
     * @author: dongdong
     * @date: 2025/1/1 14:16
     */
    public function unload($user_id=0){
        try {
            return self::where(['type'=>2])->where("user_id","in","0")->where("status=1 and is_deleted=0")->field("id,title,title_ru")->select();
        }catch (\Exception $e){
            return [];
        }
    }

    /**
     * @param $d
     * @return array|int|string
     * @notes 录入配置
     * @author: dongdong
     * @date: 2025/1/1 15:06
     */
    public function add($d){
        try {
            return self::insertGetId($d);
        }catch (\Exception $e){
            return 0;
        }
    }


    /**
     * @param int $user_id
     * @return ConfigModel[]|array|\think\Collection
     * @notes 车皮
     * @author: dongdong
     * @date: 2025/1/8 10:22
     */
    public function railway_wagon($user_id=0,$type=0){
        try {
            if($type==0){
                return self::where(['type'=>0])->where("user_id","in","0")->where("status=1 and is_deleted=0")->field("id,title,title_ru")->select();
            }else{
                return self::where(['type'=>10])->where("user_id","in","0")->where("status=1 and is_deleted=0")->field("id,title,title_ru")->select();
            }
        }catch (\Exception $e){
            return [];
        }
    }

    /**
     * @param $id
     * @return ConfigModel|array|mixed|Model
     * @notes 详情
     * @author: dongdong
     * @date: 2025/1/8 14:32
     */
    public function info($id){
        try {
            return self::where(['id'=>$id])->field("id,title,title_ru")->find();
        }catch (\Exception $e){
            return [];
        }
    }


    /**
     * @param $type
     * @return ConfigModel[]|array|\think\Collection
     * @notes 选择类型
     * @author: dongdong
     * @date: 2025/1/13 10:26
     */
    public function select_type($type){
        try {
            return self::where(['type'=>$type])->field("id,title,title_ru")->select();
        }catch (\Exception $e){
            return [];
        }
    }


}